package com.rui.patterns.combination;

import java.util.ArrayList;
import java.util.List;

/**
 * @author : [锐神NO.3]
 * @version : [v1.0]
 * @className : Menu
 * @createTime : [2022/2/23 15:30]
 * @description : [菜单类]
 */

public class Menu extends MenuComponent {

    /**
     * 菜单可以有多个子菜单或者菜单项
     */
    private List<MenuComponent> menuComponentList = new ArrayList<MenuComponent>();

    public Menu(String name, int level){
        this.name = name;
        this.level = level;
    }

    @Override
    public void add(MenuComponent component) {
        super.add(component);
    }

    @Override
    public void remove(MenuComponent component) {
        super.remove(component);
    }

    @Override
    public MenuComponent getChild(int index) {
        return super.getChild(index);
    }

    @Override
    public void print() {
        //打印菜单名称
        System.out.println(name);

        //打印子菜单名称，或者子菜单项名称
        for(MenuComponent menuComponent : menuComponentList){
            menuComponent.print();
        }
    }
}
